import React from 'react'
// ===================================================================== Temp
import SubmitForm from '#cpt/temp/SubmitForm'
// ===================================================================== global declare
const { $Lazy, $http } = window
// ===================================================================== Lazy
const Modal 	= $Lazy.state(()=>import('@antd/modal'))
const Button 	= $Lazy.state(()=>import('@antd/button'))
const Image 	= $Lazy.load(()=>import('@antd/image'))
// 
const AuditReasonModal 	= $Lazy.state(()=>import('./audit-reason-modal'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		// 提交表单列表
		formData : [
			{ label: '关联条码', name: 'spec_code', full:true, required:true }
		]
	}
	
	open = () => {
		this.modal.open({ formRef: this.formRef })
		this.fetch()
	}
	
	fetch = param => {
		$http.submit(this,'app-upload-pic/nextaudit', { param, isPull:true }).then(({pic_path, id, uuid, spec_code})=>{
			this.id = id
			this.submit = { uuid, spec_code, status:43703 }
			this.setState({ imgUrl: pic_path })
			this.formRef.setValue({ spec_code })
		})
	}
	
	render(){
		return (
			<>
				<Modal
					title	= '图片审核'
					width 	= '60%'
					height 	= '60%'
					okText	= '审核通过'
					onRef	= { ref => this.modal = ref }
					loading = { this.state.submitLoading }
					onCancel= {()=>{this.props.onRefresh()}}
					btnSuffix = { 
						<>
							<Button label='审核驳回' size='middle' style={{marginLeft:25}} onClick={()=>this.auditReasonModal.open(this.submit)} />
							<Button label='下一个' ghost size='middle' style={{marginLeft:25}} onClick={()=>this.fetch({id:this.id})} />
						</>
					}
					isFullScroll
				>
					<div className='abs_full fv p15'>
						<div>
							{ SubmitForm.call(this, { api:'app-upload-pic/audit', labelWidth:'s6', modal:false, onRefresh:()=>{this.fetch({id:this.id})} }) }
						</div>
						<Image className='ex ml20' src={this.state.imgUrl} />
					</div>
				</Modal>
				{/* 审核驳回 */}
				<AuditReasonModal onRef={ref=>this.auditReasonModal = ref} onRefresh={()=>{this.fetch({id:this.id})}} />
			</>
		)
	}
}

export default Index